from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
from recommand_demo.serializers import MovieSerializer
from utils.pagination import MovieMessagePagination
from movie.models import Douban_Movie

#　电影总页
class MovieView(APIView):
    def get(self,request):
        movie_data = Douban_Movie.objects.all().order_by('-is_new')
        paginator =MovieMessagePagination()
        result_page =paginator.paginate_queryset(movie_data,request)
        serializer =MovieSerializer(instance=result_page,many=True)
        result = {
            'count':paginator.page.paginator.count,
            # 'pageSize': paginator.page.paginator.pagesize,
            'data': serializer.data,
            'code': 2000,
            'msg': '获取成功'
        }
        return Response(result)

# 电影详情页
@api_view(['GET'])
def FilmDetailApiView(request):
    id = request.query_params.get('id')
    # print(id)
    movie_data = Douban_Movie.objects.get(id=id)
    serializer = MovieSerializer(movie_data)
    result = {
        'data': serializer.data,
        'code': 2000,
        'msg': '获取成功'
    }
    return Response(result)

# 电影主页
@api_view(['GET'])
def MovieMain(request):
    movie_data = Douban_Movie.objects.filter(is_new='2')
    serializer = MovieSerializer(movie_data,many=True)
    result = {
        'data':serializer.data,
        'code':2000,
    }
    return Response(result)
